<%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*" pageEncoding="utf-8" errorPage="" %>
<%@ page import="club325.webchat.servlet.user.UserInfoManager" %>
<%@ page import="club325.webchat.servlet.log.UserAttribute" %>
<%@ page import="club325.webchat.servlet.log.SessionAttributeManager" %>
<%@ page import="club325.webchat.model.UserInfoBean" %>
<%@ page session="false" %>

<%
	String hostname = SessionAttributeManager.getUserName(request);
	String hostrole = SessionAttributeManager.getUserRole(request);
	String username = request.getParameter("name");
	if (username == null || !UserInfoManager.checkUserName(username)) {
		//页面重定向
		request.setAttribute("tip", "用户不存在...");
		request.getRequestDispatcher("/pages/user_error.jsp").forward(request, response);
		return;
	}
	UserInfoBean info = UserInfoManager.getIndiInfo(username);
	String sex = null;
	String birthday = null;
	String address = null;
	String email = null;
	String qq = null;
	String msn = null;
	
	sex = info.getSex();
	birthday = info.getBirthday();
	address = info.getAddress();
	email = info.getEmail();
	qq = info.getQq();
	msn = info.getMsn();
	
	if (sex == null || sex.equals("")) { sex = "保密"; };
	if (birthday == null || birthday.equals("")) { birthday = "暂无信息"; };
	if (address == null || address.equals("")) { address = "暂无信息"; };
	if (email == null || email.equals("")) { email = "暂无信息"; };
	if (qq == null || qq.equals("")) { qq = "暂无信息"; };
	if (msn == null || msn.equals("")) { msn = "暂无信息"; };
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Keywords" content="WebChat,Chat" />
<meta http-equiv="Description" content="Chatting on Web" />
<title>用户信息</title>
<link href="/WebChat/style/user_lib.css" rel="stylesheet" type="text/css" />
<link href="/WebChat/style/global.css" rel="stylesheet" type="text/css" />
</head>

<body>
  <div id="main">
    <h1><%= username %>的个人信息</h1>
    <table width="500" border="0" cellspacing="10" cellpadding="0">
      <tr>
        <th width="130" scope="row">用户名 :</th>
        <td width="370"><%= username %></td>
      </tr>
      <tr>
        <th scope="row">性别 :</th>
        <td><%= sex %></td>
      </tr>
      <tr>
        <th scope="row">生日 :</th>
        <td><%= birthday %></td>
      </tr>
      <tr>
        <th scope="row">家庭地址 :</th>
        <td><%= address %></td>
      </tr>
      <tr>
        <th scope="row">email :</th>
        <td><%= address %></td>
      </tr>
      <tr>
        <th scope="row">QQ号 :</th>
        <td><%= qq %></td>
      </tr>
      <tr>
        <th scope="row">MSN帐号 :</th>
        <td><%= msn %></td>
      </tr>
    </table>
    <%
		if (!hostname.equals(username) && (hostrole.equals(UserAttribute.USERROLE_USER) || hostrole.equals(UserAttribute.USERROLE_ADMIN))) {
			List<String> friendsList = null;
			friendsList = UserInfoManager.getFriendsList(hostname);
    		if (friendsList == null || !friendsList.contains(username)) {
    		
    %>
    <a href="/WebChat/servlet/AddFriendServlet?name=<%= username %>">加为好友</a>
    <%
    		}
    	}
    %>
    <a href="#" onclick="self.close();">关闭窗口</a>
  </div>
</body>
</html>